You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
562 B
17 lines
562 B
import { getCache, setCache } from "#server/utils/context";
|
|
import { getToolById } from "../../service/tool";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const id = getRouterParam(event, "id");
|
|
if (!id) return R.throwError(400, "Missing id", null);
|
|
|
|
const cacheKey = `tool:${id}`;
|
|
const cached = await getCache(cacheKey);
|
|
if (cached) return R.success(cached);
|
|
|
|
const tool = await getToolById(id);
|
|
if (!tool) return R.throwError(404, "Tool not found", null);
|
|
|
|
await setCache(cacheKey, tool, 300);
|
|
return R.success(tool);
|
|
});
|
|
|